<template>
	<view>
		<view>
			<table-title content="续租办理表详情"></table-title>
			<view class="record-id">单号：{{processNo}}</view>
			<view class="in-center">
				<small-title content="基本资料"></small-title>
				<view class="state-bar">
					<view class="state-msg">{{state}}</view>
				</view>
			</view>
			<view class="item-table">
				<view-item name="租户名称" :value="userMsg.userCompany"></view-item>
				<view-item name="楼盘" :value="userMsg.userBuilding"></view-item>
				<view-item name="楼层" :value="userMsg.userFloor"></view-item>
				<view-item name="房间号" :value="userMsg.userRoom" :isLast="true"></view-item>
			</view>
<!-- 			<small-title v-if="state==='待申请'" content="选择楼盘"></small-title>
			<view v-if="state==='待申请'" class="small-title">
				<select-lay :value="tvalBuilding" name="name" :options="datalistBuilding" @selectitem="selectitemBuilding"></select-lay>
			</view> -->
			<small-title :isNeed="true" v-if="state==='待申请'" content="选择楼盘"></small-title>
			<view v-if="state==='待申请'" class="small-title">
				<select-lay :zindex="2" :value="tvalBuilding" name="build" :options="datalistBuilding" @selectitem="selectitemBuilding"></select-lay>
			</view>
			<small-title :isNeed="true" v-if="state==='待申请'" content="选择租户"></small-title>
			<view v-if="state==='待申请'" class="small-title">
				<select-lay :value="tvalUser" name="name" :options="datalistUser" @selectitem="selectitemUser"></select-lay>
			</view>
			<small-title :isNeed="true" content="续租询问函"></small-title>
			<view class="download-text" @click="downloadFile(0)">{{fileList[0].fileName}}</view>
			<button v-if="state==='待申请'" class="add-button" @click="uploadFile(0)">上传文件</button>
			
			<small-title :isNeed="true" content="合同续租申请表"></small-title>
			<view class="download-text" @click="downloadFile(1)">{{fileList[1].fileName}}</view>
			<button v-if="status===4 && this.userRightDetail.renewal.opeCommRight" class="add-button" @click="uploadFile(1)">上传文件</button>
			<small-title :isNeed="true" content="房屋场地使用协议"></small-title>
			<view class="download-text" @click="downloadFile(3)">{{fileList[3].fileName}}</view>
			<button v-if="status===7 && this.userRightDetail.renewal.finanCommRight" class="add-button" @click="uploadFile(3)">上传文件</button>
			<small-title :isNeed="true" content="家私配置清单"></small-title>
			<view class="download-text" @click="downloadFile(2)">{{fileList[2].fileName}}</view>
			<button v-if="status===8 && this.userRightDetail.renewal.opeCommRight" class="add-button" @click="uploadFile(2)">上传文件</button>
<!-- 			<small-title :isNeed="true" content="租赁合同"></small-title>
			<view v-for="(item,index) in fileList[4].fileName" class="download-text" @click="downloadFile(4,index)">{{fileList[4].fileName[index]}}</view>
			<button v-if="status===10 && this.userRightDetail.renewal.opeCommRight" class="add-button" @click="uploadFile(4)">上传文件</button> -->
			<small-title :isNeed="true" v-if="status>=7" content="租赁到期日期"></small-title>
			<view v-if="status>=7" class="small-title">
				<uni-datetime-picker type="date" :value="endDate" :start="currentDate" end="" @change="change" :disabled="!(status===7 && this.userRightDetail.renewal.finanCommRight)"></uni-datetime-picker>
			</view>
			<small-title :isNeed="true" v-if="status==7" content="合同签约日期"></small-title>
			<view v-if="status==7" class="small-title">
				<uni-datetime-picker type="date" :value="signDate" start="" :end="currentDate" @change="signChange" :disabled="!(this.userRightDetail.renewal.finanCommRight)"></uni-datetime-picker>
			</view>
			<small-title :isNeed="true" v-if="status==7" content="租赁面积(㎡)"></small-title>
			<input v-if="status===7" class="price-input" @input="check" v-model="measureArea" type="number" placeholder="请输入租赁面积" />
			<a v-if="status === 7">㎡</a>
			<small-title :isNeed="true" v-if="status==7" content="月租金单价(元)"></small-title>
			<input v-if="status===7" class="price-input" @input="checkPrice" v-model="unitPrice" type="number" placeholder="请输入金额" />
			<a v-if="status === 7">元</a>
			<small-title :isNeed="true" v-if="status >= 4" content="选择运营主管审批"></small-title>
			<view v-if="status >= 4" class="small-title">
				<select-lay :value="tvalVerify" name="name" :options="datalistVerify" @selectitem="selectitemVerify" :disabled="!(status == 4 && this.userRightDetail.renewal.opeCommRight)"></select-lay>
			</view>
			<small-title v-if="status >= 0" content="处理进度"></small-title>
			<proccess-bar v-if="processFlag" :proccessList="proccessListDefult"></proccess-bar>
			<view v-if="state==='待申请'" class="mix-button">
				<view class="left-part">
					<button class="left-button" @click="addOrder">发起续租</button>
				</view>
				<view class="right-part">
					<button class="right-button" @click="back">返回</button>
				</view>
			</view>
			<view v-if="status===1 && this.userRightDetail.renewal.contractCommRight" class="mix-button">
				<view class="left-part">
					<button class="left-button" @click="bbConfirm(2)">发起线下确认</button>
				</view>
				<view class="right-part">
					<button class="right-button" @click="back">返回</button>
				</view>
			</view>
			<view v-if="status===2 && this.userRightDetail.renewal.opeCommRight" class="mix-button">
				<view class="left-part">
					<button class="left-button" @click="bbConfirm(0)">已和租户确认</button>
				</view>
				<view class="right-part">
					<button class="right-button" @click="back">返回</button>
				</view>
			</view>
			<view v-if="status===4 && this.userRightDetail.renewal.opeCommRight" class="mix-button">
				<view class="left-part">
					<button class="left-button" @click="allotVerify">上传申请表</button>
				</view>
				<view class="right-part">
					<button class="right-button" @click="back">返回</button>
				</view>
			</view>
			<view v-if="status===5 && this.userRightDetail.renewal.opeVerRight" class="mix-button">
				<view class="left-part">
					<button class="left-button" @click="verify(6)">文件审核通过</button>
				</view>
				<view class="right-part">
					<button class="right-button" @click="open">驳回</button>
				</view>
			</view>
			<view v-if="status===7 && this.userRightDetail.renewal.finanCommRight" class="mix-button">
				<view class="left-part">
					<button class="left-button" @click="bbConfirm(8)">上传使用协议</button>
				</view>
				<view class="right-part">
					<button class="right-button" @click="back">返回</button>
				</view>
			</view>
			<view v-if="status===8 && this.userRightDetail.renewal.opeCommRight" class="mix-button">
				<view class="left-part">
					<button class="left-button" @click="bbConfirm(9)">上传配置清单</button>
				</view>
				<view class="right-part">
					<button class="right-button" @click="back">返回</button>
				</view>
			</view>
			<view v-if="status===10 && this.userRightDetail.renewal.opeCommRight" class="mix-button">
				<view class="left-part">
					<button class="left-button" @click="bbConfirm(11)">上传合同文件</button>
				</view>
				<view class="right-part">
					<button class="right-button" @click="back">返回</button>
				</view>
			</view>
			<view style="height: 200rpx;"></view>
		</view>
		<uni-popup ref="popup" type="dialog">
		    <uni-popup-dialog mode="input" message="成功消息" title="请输入驳回理由" :duration="2000" :before-close="true" @close="close" @confirm="confirm"></uni-popup-dialog>
		</uni-popup>
		<l-file 
		    ref="lFile" 
			@up-success="upSuccess"
		></l-file>
	</view>
</template>		

<script>
	import {
		ONLINE_SERVER_ADDRESS_BASE_2,
		syncGetOrder,
		syncGetSysUsr,
		syncGetSysUsrInfo,
	} from "../../../util/network.js"
	import {
		processHistoryList,
		getNowFormatDate
	} from "../../../util/common.js"
	export default{
		data() {
			return {
				processFlag:false,
				status:-1,
				recordId: -1,
				processNo:'待分配',
				state: '',
				userMsg:{'userName':'','userPhone':'','userCompany':'','userBuilding':'',
					'userFloor':'','userRoom':''},
				goodList:[],
				fileList:[{'fileName':'续租询问函.docx', 'fileId':-1},
						  {'fileName':'合同续租申请表.docx', 'fileId':-1},
						  {'fileName':'家私配置清单.docx', 'fileId':-1},
						  {'fileName':'房屋场地使用协议.docx', 'fileId':-1},
						  {'fileName':[], 'fileId':[]},
				],//'租赁合同.pdf','租赁合同.pdf'
				nopassReasons:'审核通过',
				proccessListDefult:[],
				token:'',
				endDate:'',
				signDate:'',
				fileType:0, //0:续租询问函 1:合同续租申请表 2:家私配置清单 3:房屋场地使用协议 4:租赁合同
				//模拟数据列表
				datalistUserbak: [],
				datalistUser: [],
				//模拟初始数据
				tvalUser: "value2",
				//模拟数据列表
				datalistBuilding: [],
				//模拟初始数据
				tvalBuilding: "value2",
				datalistVerify: [],
				//模拟初始数据
				tvalVerify: "",
				rentUserId:-1,
				measureArea:0,
				unitPrice:0,
				currentDate:'',
			}
		},
		methods: {
			check: function(index) {
				//正则表达试
				let temp = (this.measureArea.match(/^\d*(\.?\d{0,2})/g)[0]) || null
				//重新赋值给input
				this.$nextTick(() => {
					this.measureArea= temp
				})
			},
			checkPrice: function(index) {
				//正则表达试
				let temp = (this.unitPrice.match(/^\d*(\.?\d{0,2})/g)[0]) || null
				//重新赋值给input
				this.$nextTick(() => {
					this.unitPrice= temp
				})
			},
			selectitemUser(index, item) {
				console.log(item)
				if (index >= 0) {
					this.tvalUser = item.value;
					let userJson = JSON.parse(item.value)
					this.userMsg.userCompany = userJson.name
					this.userMsg.userBuilding = userJson.title
					this.userMsg.userFloor = userJson.floor
					this.userMsg.userRoom = userJson.houseNumber
					this.rentUserId = userJson.id
				} else {
					this.tvalUser = ""
				}
			},
			selectitemBuilding(index, item) {
				console.log(item)
				if (index >= 0) {
					this.tvalBuilding = item.value;
					this.datalistUser = []
					this.datalistUserbak.forEach(item => {
						if(parseInt(this.tvalBuilding) == JSON.parse(item.value).buildId){
							this.datalistUser.push(item)
						}
					})
				} else {
					this.tvalBuilding = ""
				}
			},
			selectitemVerify(index, item) {
				console.log(item)
				if (index >= 0) {
					this.tvalVerify = item.value;
				} else {
					this.tvalVerify = ""
				}
			},
			change(value){
				this.endDate = value + " 23:59:59"
				console.log(this.endDate)
			},
			signChange(value){
				this.signDate = value + " 23:59:59"
				console.log(this.signDate)
			},
			open() {
				this.$refs.popup.open()
			},
			/**
			 * 点击取消按钮触发
			 * @param {Object} done
			 */
			close() {
				// TODO 做一些其他的事情，before-close 为true的情况下，手动执行 close 才会关闭对话框
				// ...
				this.$refs.popup.close()
			},
			/**
			 * 点击确认按钮触发
			 * @param {Object} done
			 * @param {Object} value
			 */
			confirm(value) {
				this.$refs.popup.close()
				if(value == ""){
					uni.showModal({
						content:'理由不能为空',
						showCancel:false
					});
					this.$refs.popup.close()
				}else{
					this.nopassReasons = "运营主管已驳回，理由：" + value
					this.verify(4)
					// TODO 做一些其他的事情，手动执行 close 才会关闭对话框
					// ...
					this.$refs.popup.close()
				}
			},
			
			upSuccess(e){
				console.log(e)
				if(this.fileType == 4){
					this.fileList[this.fileType].fileName.push(e.fileName)
					this.fileList[this.fileType].fileId.push(e.data)
				}else{
					this.fileList[this.fileType].fileName = e.fileName
					this.fileList[this.fileType].fileId = e.data
				}

			},
			
			uploadFile(status){
				this.fileType = status
				this.$refs.lFile.upload({
				    // #ifdef APP-PLUS
				    //（app端必传）nvue页面使用时请查阅nvue获取当前webview的api，当前示例为vue窗口
				    currentWebview: this.$mp.page.$getAppWebview(),
				    // #endif
				    //替换为你的上传接口地址
				    url: `${ONLINE_SERVER_ADDRESS_BASE_2}/file/upload`,
				    // 服务端接收附件的key
				    name: 'file',
				    //根据你接口需求自定义 (优先不传content-type,安卓端无法收到参数再传)
				    header: {
						'Authorization': this.token,
				        // 'Authorization': 'bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mbyI6eyJ1c2VyTmFtZSI6',
				        // 'uid': '27682',
				        // 'client': 'app',
				        // 'accountid': 'DPOA9487'
				    },
				
				    // 限制选择附件的大小上限，默认10M
				    // maxSize: 20,
				
				    // 若需要在body单独添加附件名或附件大小如下方式传入组件：
				    // addName: '后端要的附件名称字段key,此处请勿写name的同值如(file)，会覆盖name',
				    // addSize: '后端要的附件大小字段key'
				
				    // body参数直接写key,value,如：
				    // date: '2020-1-1',
				    // key2: 'value2',
				});
			},
			
			downloadFile(fileType,index){
				let fileId = 0
				let errMsg = ""
				fileId = this.fileList[fileType].fileId
				switch(fileType) {
					 case 0:
						errMsg = "待合同专员上传"
						break;
					 case 1:
						errMsg = "待楼层管家上传"
						break;
					 case 2:
						errMsg = "待楼层管家上传"
						break;
					 case 3:
						errMsg = "待财务专员上传"
						break;
					 case 4:
						console.log(this.fileList[fileType])
						fileId = this.fileList[fileType].fileId[index]
						errMsg = "待楼层管家扫描上传"
						break;
				}
				if(!(parseInt(fileId) > 0)){
					uni.showModal({
						content:errMsg,
						showCancel:false
					})
					return 0
				}
				this.$refs.lFile.download({
					url:`${ONLINE_SERVER_ADDRESS_BASE_2}/file/download/` + fileId,
					token:this.token,
				})
				.then(path=>{
				    // 打开文件
				    this.$refs.lFile.open(path);
				});
			},
			//废弃
			async downloadOrderFile(fileType){
				let fileId = 0
				if(fileType == 0){
					fileId = this.docxFileId
				}else{
					fileId = this.pdfFileId
				}
				const res = await uni.downloadFile({
					url:`${ONLINE_SERVER_ADDRESS_BASE_2}/file/download/` + fileId,
					header: {
						'Authorization': this.token,
					},
				})
				return new Promise((resolve, reject) => {
				        resolve(res[1].tempFilePath)
				})
			},
			
			verify(status){
				console.log("[info]","运营主管审核：" + this.recordId)
				if(status == 6){
					if(this.userRightDetail.knotCommission.primeAuth == 1){
						this.nopassReasons = "运营主管审核通过"
					}else{
						this.nopassReasons = "楼层管家审核通过"
					}
				}
				uni.request({
					url:`${ONLINE_SERVER_ADDRESS_BASE_2}/renew/verify/` + this.recordId,
					header: {
						'Authorization': this.token,
					},
					data: {
						status:status,
						commentMsg:this.nopassReasons,                       //操作信息
					},
					method:'POST',
					success: function (res) {
						console.log("运营主管审核成功",res);
						if(res.data.code == 200){
							uni.navigateBack()
						}
					},
					fail: (res) => {
						console.log("运营主管审核调用失败")
					}
				})
			},
			
			allotVerify(){
				console.log("[info]","楼层管家指派审批：" + this.recordId)
				if(!(this.fileList[1].fileId > 0) || (this.tvalVerify == "")){
					uni.showModal({
						content:'请上传合同续租申请表并指定待审批主管',
						showCancel:false
					})
					return 0
				}
				let commentMsg = ''
				if(this.userRightDetail.knotCommission.primeAuth == 1){
					commentMsg = "运营主管已上传合同续租申请表"
				}else{
					commentMsg = "楼层管家已上传合同续租申请表"
				}
				uni.request({
					url:`${ONLINE_SERVER_ADDRESS_BASE_2}/renew/allot-verify/` + this.recordId,
					header: {
						'Authorization': this.token,
					},
					data: {
						verifierId:this.tvalVerify,
						applyFileId:this.fileList[1].fileId.toString(),
						commentMsg:commentMsg,                       //操作信息
					},
					method:'POST',
					success: function (res) {
						console.log("楼层管家指派审批成功",res);
						if(res.data.code == 200){
							uni.navigateBack()
						}
					},
					fail: (res) => {
						console.log("楼层管家指派审批调用失败")
					}
				})
			},
			
			bbConfirm(status){
				console.log("[info]","bb-confirm：" + this.recordId)
				let fileId = -1
				let dueTime = ''
				let signTime = ''
				let commentMsg = ''
				switch(status) {
				     case 0:
						if(this.userRightDetail.renewal.primeAuth == 11){
							commentMsg = "合同主管已生成《续租受理回执函》"
						}else{
							commentMsg = "合同专员已生成《续租受理回执函》"
						}
				        break;
				     case 2:
						if(this.userRightDetail.knotCommission.primeAuth == 1){
							commentMsg = "运营主管已线下联系到租户,待租户确认续租情况"
						}else{
							commentMsg = "楼层管家已线下联系到租户,待租户确认续租情况"
						}
				        break;
					 case 8:
						if(!(this.fileList[3].fileId > 0)){
							uni.showModal({
								content:'请上传房屋场地使用协议',
								showCancel:false
							})
							return 0
						}
						 if(this.endDate == ""){
							uni.showModal({
								content:'请输入合同到期日期',
								showCancel:false
							})
							return 0
						 }
						 if(this.signDate == ""){
							uni.showModal({
								content:'请输入合同签约日期',
								showCancel:false
							})
							return 0
						 }
						 if(this.measureArea <= 0){
							uni.showModal({
								content:'请输入有效租赁面积',
								showCancel:false
							})
							return 0
						 }
						 if(this.unitPrice <= 0){
							uni.showModal({
								content:'请输入有效月租金单价',
								showCancel:false
							})
							return 0
						 }
						signTime = this.signDate
						dueTime = this.endDate
						if(this.userRightDetail.renewal.primeAuth == 5){
							commentMsg = "财务主管已上传《房屋场地使用协议》,待租户确认"
						}else{
							commentMsg = "财务专员已上传《房屋场地使用协议》,待租户确认"
						}
						fileId = this.fileList[3].fileId.toString()
					    break;
					 case 9:
						 if(!(this.fileList[2].fileId > 0)){
							uni.showModal({
								content:'请上传家私配置清单',
								showCancel:false
							})
							return 0
						 }
						if(this.userRightDetail.knotCommission.primeAuth == 1){
							commentMsg = "运营主管已上传家私配置清单"
						}else{
							commentMsg = "楼层管家已上传家私配置清单"
						}
						fileId = this.fileList[2].fileId.toString()
					    break;
					 // case 11:
						//  if(!(this.fileList[4].fileId.length > 0)){
						// 	uni.showModal({
						// 		content:'请上传租赁合同文件',
						// 		showCancel:false
						// 	})
						// 	return 0
						//  }
						//  if(this.signDate == ""){
						// 	uni.showModal({
						// 		content:'请输入合同签约日期',
						// 		showCancel:false
						// 	})
						// 	return 0
						//  }
				  //       commentMsg = '楼层管家已扫描并上传新的租赁合同文件,办结'
						// signTime = this.signDate
						// dueTime = this.endDate
						// fileId = JSON.stringify(this.fileList[4].fileId).replace('[','').replace(']','')
					 //    break;
				     default:
						uni.showModal({
							content:'输入错误',
							showCancel:false
						})
						return 0
				} 
				console.log(status)
				console.log(fileId)
				console.log(dueTime)
				console.log(signTime)
				console.log(commentMsg)
				console.log(this.measureArea)
				uni.request({
					url:`${ONLINE_SERVER_ADDRESS_BASE_2}/renew/bb-confirm/` + this.recordId,
					header: {
						'Authorization': this.token,
					},
					data: {
						status:status,
						fileId:fileId,
						dueTime:dueTime,
						signTime:signTime,
						measureArea:this.measureArea,
						unitPrice:this.unitPrice,
						commentMsg:commentMsg,                       //操作信息
					},
					method:'POST',
					success: function (res) {
						console.log("bb-confirm成功",res);
						if(res.data.code == 200){
							uni.navigateBack()
						}
					},
					fail: (res) => {
						console.log("bb-confirm调用失败")
					}
				})
			},
			
			addOrder(){
				if(this.rentUserId == -1 || this.fileList[0].fileId == -1){
					uni.showModal({
						content:'请选择租户并上传续租询问函文件',
						showCancel:false
					})
					return 0
				}
				if(this.userRightDetail.renewal.primeAuth == 11){
					this.nopassReasons = "合同主管已上传续租询问函并发起续租"
				}else{
					this.nopassReasons = "合同专员已上传续租询问函并发起续租"
				}
				uni.request({
					url:`${ONLINE_SERVER_ADDRESS_BASE_2}/renew/add`,
					header: {
						'Authorization': this.token,
					},
					data: {
						qfUserId:this.rentUserId,
						fileId:this.fileList[0].fileId,
						commentMsg: this.nopassReasons                       //操作信息
					},
					method:'POST',
					success: function (res) {
						console.log("发起续租成功",res);
						if(res.data.code == 200){
							uni.navigateBack()
						}
					},
					fail: (res) => {
						console.log("发起续租调用失败")
					}
				})
			},
			
			getOrder(){
				let a = syncGetOrder("renew/show/" + this.recordId)
				 a.then((res)=>{
					 console.log("异步",res)
					 if(res.data.code == 200){
						 console.log("详细",res.data.data)
						 this.status = parseInt(res.data.data.status)
						 switch(this.status) {
						 	 case 0:
						 		this.state = "待确认续租"
						 		break;
						 	 case 1:
						 		this.state = "待合同处理"
						 		break;
						 	 case 2:
						 		this.state = "待管家处理"
						 		break;
						 	 case 3:
						 		this.state = "用户不续租"
						 		break;
						 	 case 4:
						 		this.state = "待管家上传"
						 		break;
						 	 case 5:
						 		this.state = "待运营审核"
						 		break;
						 	 case 6:
						 		this.state = "待用户确认"
						 		break;
						 	 case 7:
						 		this.state = "待上传协议"
						 		break;
						 	 case 8:
						 		this.state = "待管家上传"
						 		break;
						 	 case 9:
						 		this.state = "待用户确认"
						 		break;
						 	 case 10:
						 		this.state = "已完成续租"
						 		break;
						 	 case 11:
						 		this.state = "已完成续租"
						 		break;
						      default:
						         this.state = "待申请"
						 } 
						 this.processNo = res.data.data.processNo
						 this.userMsg.userCompany = res.data.data.createUserInfo.name
						 this.userMsg.userBuilding = res.data.data.createUserInfo.title
						 this.userMsg.userFloor = res.data.data.createUserInfo.floor
						 this.userMsg.userRoom = res.data.data.createUserInfo.houseNumber
						 this.fileList[0].fileId = res.data.data.inquiryFileId
						 this.fileList[1].fileId = res.data.data.applyFileId
						 this.fileList[2].fileId = res.data.data.configFileId
						 this.fileList[3].fileId = res.data.data.treatyFileId
						 try{
						 	let tempArray = res.data.data.contractFileId.split(',')
						 	tempArray.forEach((item,index) => {
						 		this.fileList[4].fileId.push(item)
								let tempIndex = index + 1
								let temp ='租赁合同' + tempIndex + '.pdf'
								this.fileList[4].fileName.push(temp)
						 	})
						 }catch(e){
						 	//TODO handle the exception
						 }
						 this.proccessListDefult = processHistoryList(res.data.data.processDetail)
						 this.processFlag = true
						 if(this.status > 4){      //如果管家已指派了运营主管，则查询当前主管信息
							 let b = syncGetSysUsrInfo("systemuser/show/" + parseInt(res.data.data.operationSupervisorId));
							 b.then((v)=>{
							 	 if(v.data.code == 200){
							 		 let temp = {label: "",value: ""}
							 		 temp.label = v.data.data.name
							 		 temp.value = res.data.data.operationSupervisorId
							 		this.datalistVerify.push(temp)
							 		this.tvalVerify = temp.value
							 		this.$forceUpdate()
							 	}
							 })
						 }
						 if(this.status >= 8){      //如果是合同专员已生成了租赁合同，则读取已写入的合同到期日期
							 this.endDate = res.data.data.dueTime.replace("T"," ")
						 }
						 
						 if(this.status == 4){     //如果是管家待选择主管审核状态，则查询运营主管权限的所有员工
							 var areaId = uni.getStorageSync("currentUser").area_id
							 console.log("查询工作人员",areaId)
							 let a = syncGetSysUsr("systemuser/area-auth/users", areaId, 1);
							 a.then((res)=>{
							 	 if(res.data.code == 200){
							 		let resList = res.data.data.systemUserList
							 		resList.forEach((item,key) => {
							 			let temp = {label: "",value: ""}
							 			temp.label = item.name
							 			temp.value = item.id.toString()
							 			this.datalistVerify.push(temp)
							 		});
							 		this.$forceUpdate()
							 	}
							 })
						 }
						 
					}
				})
			},
			
			getUserList(){
				let _this = this
				uni.request({
					url:`${ONLINE_SERVER_ADDRESS_BASE_2}/user/list`,
					header: {
						'Authorization': this.token,
					},
					data: {
						pageNo:0,
						pageSize:100,
					},
					method:'GET',
					success: function (res) {
						console.log("查询租户",res);
						if(res.data.code == 200){
							let resList = res.data.data.userList
							resList.forEach((item,key) => {
								let temp = {label: "",value: ""}
								temp.label = item.name + '(' + item.houseNumber + ')'
								temp.value = JSON.stringify(item)
								_this.datalistUserbak.push(temp)
								_this.getBuildingList(item)
							});
							_this.$forceUpdate()
						}
					},
					fail: (res) => {
						console.log("查询租户失败")
					}
				})
			},
			
			getBuildingList(item){
				let flag = true
				for (var i = 0; i < this.datalistBuilding.length; i++) {
					if(this.datalistBuilding[i].value == item.buildId){
						flag = false
						break
					}
				}
				if(flag){
					let temp = {}
					temp.label = item.title
					temp.value = item.buildId
					this.datalistBuilding.push(temp)
				}
			},
			
			back(){
				uni.navigateBack()
			},
		},
		onLoad(option) {
			//传入单号
			let  newdate=getNowFormatDate()
			this.currentDate = newdate
			if(uni.getStorageSync('userinfo') != null){
				this.userRightDetail = uni.getStorageSync("userRight")
				this.recordId = option.id
				this.state = option.state
				this.token = uni.getStorageSync('token')
				this.getUserList()
			}else{
				uni.navigateTo('../../login/login')
			}
		},
		mounted() {
			//如果是新建表单则不查询
			if(this.state != '待申请'){
				this.getOrder()
			}
		}
	}
</script>

<style>
	page{
		background-color: #ffffff
	}
	.record-id{
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
	}
	.state-bar{
		display: flex;
		align-items: center;
		color: #FFFFFF;
		background-color: #DD524D;
		width: 260rpx;
		justify-content: center;
		margin-left: auto;
		margin-right: 50rpx;
		font-size: 30rpx;
		border-radius: 50rpx;
		height: 50rpx;
	}
	.state-msg{
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.item-table{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.mix-button{
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.left-part{
		float: right;
	}
	.right-part{
		float: left;
	}
	.left-button{
		background-color: #FF0000;
		border-radius: 50rpx 0 0 50rpx;
		color: #FFFFFF;
		width: 300rpx;
		font-size: 30rpx;
	}
	.right-button{
		background-color: #0000FF;
		border-radius: 0 50rpx 50rpx 0;
		color: #FFFFFF;
		width: 300rpx;
		font-size: 30rpx;
	}
	.in-center{
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.add-button {
		border-width: 0px;
		align-items: center;
		justify-content: center;
		margin: 30rpx 0 40rpx 250rpx;
		height: 50rpx;
		width: 250rpx;
		display: flex;
		color: #22B242;
	}
	.download-text {
	  -webkit-box-sizing: content-box;
	  -moz-box-sizing: content-box;
	  box-sizing: content-box;
	  border: none;
	  font: normal 16px/1 "Times New Roman", Times, serif;
	  color: rgba(18,25,232,1);
	  text-decoration: underline;
	  -o-text-overflow: ellipsis;
	  text-overflow: ellipsis;
	  margin-left: 60rpx;
	  margin-bottom: 10rpx;
	}
	.small-title{
		margin: 20rpx 0 20rpx 50rpx;
		width: 87%;
	}
	.price-input {
	  display: inline-block;
	  -webkit-box-sizing: content-box;
	  -moz-box-sizing: content-box;
	  box-sizing: content-box;
	  width: 50%;
	  padding: 9px 0 6px 20px;
	  border: 1px solid #b7b7b7;
	  -webkit-border-radius: 3px;
	  border-radius: 3px;
	  font: normal 16px/normal "Times New Roman", Times, serif;
	  color: rgba(0,142,198,1);
	  -o-text-overflow: clip;
	  text-overflow: clip;
	  background: rgba(252,252,252,1);
	  -webkit-box-shadow: 2px 2px 2px 0 rgba(0,0,0,0.2) inset;
	  box-shadow: 2px 2px 2px 0 rgba(0,0,0,0.2) inset;
	  text-shadow: 1px 1px 0 rgba(255,255,255,0.66) ;
	  -webkit-transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
	  -moz-transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
	  -o-transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
	  transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
	  margin-left: 50rpx;
	  margin-right: 30rpx;
	}
</style>
